﻿using System;
using Engine;
using Engine.Graphics;
using Game;

namespace SAGhoul.Blocks
{
	public class Trophy64Block : Block
	{
		readonly BlockMesh m_standaloneMesh = new();
		Texture2D m_texture;

		public override void Initialize()
		{
			Model model = ContentManager.Get<Model>("Models/Trophy");
			m_texture = ContentManager.Get<Texture2D>("Textures/Trophy");
			ModelMesh trophyMesh = model.FindMesh("Trophy");
			ModelMesh chunkMesh = model.FindMesh("Chunk");
			Matrix boneAbsoluteTransform1 = BlockMesh.GetBoneAbsoluteTransform(trophyMesh.ParentBone);
			Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(chunkMesh.ParentBone);
			m_standaloneMesh.AppendModelMeshPart(trophyMesh.MeshParts[0], Matrix.CreateTranslation(boneAbsoluteTransform1.Translation) * Matrix.CreateScale(1.3f) * Matrix.CreateRotationX(-(float)Math.PI / 2f) , makeEmissive: false, flipWindingOrder: false, doubleSided: true, flipNormals: false, Color.White);
			m_standaloneMesh.AppendModelMeshPart(chunkMesh.MeshParts[0], Matrix.CreateTranslation(boneAbsoluteTransform2.Translation) * Matrix.CreateScale(1.3f) * Matrix.CreateRotationX(-(float)Math.PI / 2f) , makeEmissive: true, flipWindingOrder: false, doubleSided: true, flipNormals: false, Color.White);
			base.Initialize();
		}

		public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
		{
		}

		public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
		{
			BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneMesh, m_texture, color, size, ref matrix, environmentData);
		}

		public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
		{
			return LanguageControl.GetBlock("Trophy64Block:0", SAGhoulsManager.WholeDays.ToString()) + base.GetDisplayName(subsystemTerrain, value);
		}
	}
}
